package com.weetop.aklyscan.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.OutRecordListBean;
import com.weetop.aklyscan.bean.RecordBean;
import com.weetop.aklyscan.presenter.RecordPresent;
import com.weetop.aklyscan.view.RecordView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OutRecordActivity extends BaseActivity<RecordPresent> implements RecordView, CommonRecyclerAdapter.OnItemClickListener {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.tv_xiang)
    TextView tv_xiang;
    @BindView(R.id.txt_title)
    TextView txt_title;
    private CommonRecyclerAdapter<OutRecordListBean> adapter;
    private List<OutRecordListBean> list = new ArrayList<>();
    private String order_sn, date;

    @Override
    protected RecordPresent createPresenter() {
        return new RecordPresent(this, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_in_record);
        ButterKnife.bind(this);
        order_sn = getIntent().getStringExtra("order_sn");
        date = getIntent().getStringExtra("time");
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<OutRecordListBean>(mActivity, R.layout.item_record, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, OutRecordListBean item, int position) {
                helper.setText(R.id.tv_xuhao, position + 1 + "");
                helper.setText(R.id.tv_sn_code, item.getCode());
                helper.setText(R.id.tv_model, item.getGoods_model());
                helper.setText(R.id.tv_name, item.getGoods_name());
                helper.setText(R.id.tv_xiang, item.getCase_code());
            }
        };
        tv_xiang.setText("外箱编号");
        txt_title.setText("出库记录详情");
        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);
        mPresenter.Into30(order_sn, date);
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {

    }

    @Override
    public void getInto30Success(BaseModel<List<OutRecordListBean>> o) {
        List<OutRecordListBean> listBeans = o.getData();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
    }
}
